﻿Public Class MASHOSP
    Private HOSPID As Integer = Nothing
    Private HOSPCODE As String = Nothing
    Private HOSPNAME As String = Nothing
    Private FRMHN As String = Nothing
    Private DISPYR As Integer = Nothing
    Private LANGUCODE As String = Nothing
    Private CODECOUNTRY As Integer = Nothing
    Private CODECHANGWAT As Integer = Nothing
    Private AMPID As Integer = Nothing
    Private TMBID As Integer = Nothing
    Private selectMashosp = "SELECT `HOSPID`, `hospcode` AS 'รหัสสถานบริการ', `hospname` AS 'ชื่อสถานบริการ' , `frmhn` AS 'รูปแบบ HN', `langucode` AS 'รหัสภาษา', mascountry.`CODECOUNTRY`, maschangwat.`CODECHANGWAT`, masampur.`AMPID`, mastambon.`TMBID`, mascountry.`country` AS 'ประเทศ', maschangwat.`changwat` AS 'จังหวัด', masampur.`ampur` AS 'อำเภอ', mastambon.`tambon` AS 'ตำบล' FROM mashosp LEFT JOIN (SELECT * FROM mascountry ) AS mascountry ON mashosp.`codecountry` = mascountry.`codecountry` LEFT JOIN (SELECT * FROM maschangwat ) AS maschangwat ON mashosp.`codechangwat` = maschangwat.`codechangwat` LEFT JOIN (SELECT * FROM masampur )AS masampur ON mashosp.`ampid` = masampur.`ampid` LEFT JOIN (SELECT * FROM mastambon )AS mastambon ON mashosp.`tmbid` = mastambon.`tmbid` ORDER BY `hospid` "
    Dim connect As CONDB = CONDB.NewConnection()
    Property selectMashosp_() As String
        Get
            Return selectMashosp
        End Get
        Set(value As String)

        End Set
    End Property
    Property TMBID_() As Integer
        Get
            Return TMBID
        End Get
        Set(value As Integer)
            TMBID = value
        End Set
    End Property
    Property AMPID_() As Integer
        Get
            Return AMPID
        End Get
        Set(value As Integer)
            AMPID = value
        End Set
    End Property
    Property CODECHANGWAT_() As Integer
        Get
            Return CODECHANGWAT
        End Get
        Set(value As Integer)
            CODECHANGWAT = value
        End Set
    End Property
    Property CODECOUNTRY_() As Integer
        Get
            Return CODECOUNTRY
        End Get
        Set(value As Integer)
            CODECOUNTRY = value
        End Set
    End Property
    Property LANGUCODE_() As String
        Get
            Return LANGUCODE
        End Get
        Set(value As String)
            LANGUCODE = value
        End Set
    End Property
    Property DISPYR_() As Integer
        Get
            Return DISPYR
        End Get
        Set(value As Integer)
            DISPYR = value
        End Set
    End Property
    Property FRMHN_() As String
        Get
            Return FRMHN
        End Get
        Set(value As String)
            FRMHN = value
        End Set
    End Property
    Property HOSPNAME_() As String
        Get
            Return HOSPNAME
        End Get
        Set(value As String)
            HOSPNAME = value
        End Set
    End Property

    Property HOSPCODE_() As String
        Get
            Return HOSPCODE
        End Get
        Set(value As String)
            HOSPCODE = value
        End Set
    End Property
    Property HOSPID_() As Integer
        Get
            Return HOSPID
        End Get
        Set(value As Integer)
            HOSPID = value
        End Set
    End Property
    Public Sub insertMashosp()
        If TypeOf HOSPNAME Is String And TypeOf HOSPCODE Is String Then
            If connect.GetTable("SELECT `hospid` FROM mashosp WHERE  `hospcode` = '" & HOSPCODE & "' AND `hospname` = '" & HOSPNAME & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูลส่วนนี้อยู่ในระบบแล้ว", MsgBoxStyle.Critical)
            Else
                connect = CONDB.NewConnection()
                connect.BeginTrans()
                Try
                    'Dim productCode As Integer
                    'productCode = connect.ExecuteScalar("INSERT INTO MASPRODUCT (`PRDCAT`, `PRDNAME`, `CCODE`, `RCODE`,`OPDPRC`,`IPDPRC`) VALUES ('3', '" & OPERATENAME_EN & "', '" & CCODE & "', '" & RCODE & "','" & OPDPRC & "','" & IPDPRC & "'); SELECT LAST_INSERT_ID();")
                    Dim sql As String
                    sql = "INSERT INTO MASHOSP"
                    sql += "(`hospcode`,`hospname`,`frmhn`,`langucode`,`tmbid`,`ampid`,`codechangwat`,`codecountry`)"
                    sql += "VALUES ("
                    sql += "'" & HOSPCODE & "',"
                    sql += "'" & HOSPNAME & "',"
                    sql += "'" & FRMHN & "',"
                    'sql += "'" & DISPYR & "',"
                    sql += "'" & LANGUCODE & "',"
                    sql += "'" & TMBID & "',"
                    sql += "'" & AMPID & "',"
                    sql += "'" & CODECHANGWAT & "',"
                    sql += "'" & CODECOUNTRY & "')"
                    connect.ExecuteNonQuery(sql)
                    connect.CommitTrans()
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
                Catch ex As Exception
                    connect.RollbackTrans()
                    MsgBox(ex.ToString)
                Finally
                    connect.Dispose()
                End Try
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร", MsgBoxStyle.Critical)
        End If
    End Sub

    Public Sub editMashosp()
        If TypeOf HOSPNAME Is String And TypeOf HOSPCODE Is String Then
            connect = CONDB.NewConnection()
            connect.BeginTrans()
            Try
                Dim sql As String
                sql = "UPDATE mashosp SET"
                sql += "`hospcode` = '" & HOSPCODE & "',"
                sql += "`hospname` = '" & HOSPNAME & "',"
                sql += "`frmhn` = '" & FRMHN & "',"
                sql += "`dispyr` = '" & DISPYR & "',"
                sql += "`langucode` = '" & LANGUCODE & "',"
                sql += "`tmbid` = '" & TMBID & "',"
                sql += "`ampid` = '" & AMPID & "',"
                sql += "`codechangwat` = '" & CODECHANGWAT & "',"
                sql += "`codecountry` = '" & CODECOUNTRY & "' "
                sql += "WHERE `hospid` = '" & HOSPID & "';"
                connect.ExecuteNonQuery(sql)
                connect.CommitTrans()
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
            Catch ex As Exception
                connect.RollbackTrans()
                MsgBox(ex.ToString)
            Finally
                connect.Dispose()
            End Try
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร", MsgBoxStyle.Critical)
        End If
    End Sub
End Class
